/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package validation;

import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import javax.swing.JComponent;
import javax.swing.JTextField;

/**
 *
 * @author Usuario
 */
public class KeyLimiter extends KeyAdapter{

    private int limite;
    private JComponent c;
    
    public KeyLimiter(int limit, JComponent c){
        this.limite=limit;
        this.c=c;
    }
    
    @Override
    public void keyTyped(KeyEvent e) {
        if(c instanceof JTextField){
            if(((JTextField)c).getText().length()==limite)
                e.consume();
        }
    }
}
